package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Role;
import cn.wolfcode.mapper.PermissionMapper;
import cn.wolfcode.mapper.RoleMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
   private RoleMapper roleMapper;


    @Override
    public List list() {
        List<Role> roles = roleMapper.selectAll();
        return roles;
    }



    @Override
    public void update(Role role) {
        roleMapper.updateByPrimaryKey(role);
    }

    @Override
    public void insert(Role role) {
        roleMapper.insert(role);
    }



    @Override
    public PageInfo<Role> queryList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Role> rolePageInfo = roleMapper.queryList(qo);
        return new PageInfo<>(rolePageInfo);
    }

    @Override
    public void delete(Long id) {
        roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertAll(Long rId, Long pId) {
        roleMapper.insertAll(rId,pId);
    }

    @Override
    public List selectPerAndRoel(Long id) {
        List list = roleMapper.selectPerAndRoel(id);
        return list;
    }

    @Override
    public void delteAll(Long rId) {
        roleMapper.deleteAll(rId);
    }


    @Override
    public Role get(Long id) {
        Role role = roleMapper.selectByPrimaryKey(id);
        return role;
    }
}
